package net.util;

import org.lwjgl.opengl.Display;
import org.lwjgl.util.Rectangle;

public class MathUtil 
{
	private MathUtil()
	{
		
	}
	
	public static final double PI_2 = Math.PI * 2, PI_1_2 = Math.PI / 2, PI_1_4 = Math.PI / 4;
	
	public static double distance(float x1, float y1, float x2, float y2)
	{/*
		if (x1 == x2)
		{
			return y2-y1;
		}
		if (y1 == y2)
		{
			return x2-x1;
		}	*/
		return Math.hypot(x2-x1, y2-y1);
	}
	
	public static double direction(float x1, float y1, float x2, float y2)
	{
		if (y1 == y2)
		{
			return (x1 > x2) ? 180D : 0D;
		}
		if (x1 == x2)
		{
			return (y1 > y2) ? 90D : 270D;
		}
		
		return Math.toDegrees((float)(Math.atan2( (y2-y1),(x2-x1) )));
	}

	public static boolean inRegion(int x, int y, Rectangle r, boolean screenCompensate)
	{
		if (screenCompensate)
		{
			y = Display.getHeight() - y;
		}
		
		return x >= r.getX() && x <= r.getX() + r.getWidth() && y >= r.getY() && y <= r.getY() + r.getHeight();
	}
	
	public static double lx(double length, double angle)
	{
		return Math.cos(angle) * length;
	}
	
	public static double ly(double length, double angle)
	{
		return Math.sin(angle) * length;
	}
}
